<html>
<style type="text/css">
body {
	font-family:verdana,arial,sans-serif;
	font-size:10pt;
	margin:30px;
	background-color:#ffcc00;
	}
</style>

<a href ="editbook.php" target = "_top">Edit another Book</a><br />

</html>

<?php

if(isset($_POST['origISBN']))
{
    $username="bsc353_4";
    $password="sonbeans";
    $database="bsc353_4";
    mysql_connect("clipper.encs.concordia.ca",$username,$password);

    @mysql_select_db($database) or die ("Unable to select database");


    $originalISBN = $_POST['origISBN'];
    

    if (isset($_POST['delete'])) //if user chose to delete
    {
        $query = "DELETE FROM Book WHERE ISBN = '$originalISBN'";
    }
    else //user chose to edit one or more of the book's fields
    {
        $price= intval($_POST['price']) * 100;
        $year=$_POST['year'];
        $ISBN=$_POST['ISBN'];
        $author=$_POST['author'];
        $subject=$_POST['subject'];
        $publisher=$_POST['publisher'];
        $title=$_POST['title'];
        $quantity= intval($_POST['quantity']);

        $query="UPDATE Book SET price=$price, year= '$year', author = '$author', subject = '$subject', publisher = '$publisher',
        title = '$title', yearToDateQtySold = $quantity, ISBN = '$ISBN' WHERE ISBN = '$originalISBN';";
    }
    
    //echo $query;
    mysql_query($query) or die ("failed to add record");

    if(isset($_POST['save']))
        echo "Record successfully edited";
    else if(isset($_POST['delete']))
        echo "Record successfully deleted";
	
    mysql_close();
}
else
{
    echo "need to choose a book first";
}



?> 

